package predict.app.music;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private String hight = null;
    private String sexx = "M";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button jisuan = (Button)findViewById(R.id.button);
        final EditText tall = (EditText)findViewById(R.id.editText3);
        final RadioGroup sex = (RadioGroup)findViewById(R.id.rg_sex);

        jisuan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                hight = tall.getText().toString();
                if(hight == "") {
                    Toast.makeText(MainActivity.this, "体重不能为空", Toast.LENGTH_SHORT).show();
                    return;
                }
                double height = Double.parseDouble(hight);
                sex.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(RadioGroup arg0, int checkedId) {
                        if(checkedId == R.id.rb_male) {
                            sexx = "M";
                        } else {
                            sexx = "F";
                        }
                    }
                });
                Intent intent = new Intent();
                intent.setClass(MainActivity.this, Result.class);
                Bundle bundle = new Bundle();
                bundle.putDouble("height", height);
                bundle.putString("sex", sexx);
                intent.putExtras(bundle);
                startActivity(intent);
            }
        });
    }
}
